package com.itheima.d6_jdk8_time;

import java.time.*;

public class Test3_LocalDateTime {
    public static void main(String[] args) {
        // 0、获取本地日期和时间对象。
        LocalDateTime ldt = LocalDateTime.now(); // 年 月 日 时 分 秒 纳秒


        // 1、可以获取日期和时间的全部信息
        // 年
        int year = ldt.getYear();
        System.out.println("year = " + year);
        // 月
        Month month = ldt.getMonth();
        System.out.println("month = " + month);
        // 日
        int dayOfMonth = ldt.getDayOfMonth();
        System.out.println("dayOfMonth = " + dayOfMonth);
        //一年中的第几天
        int dayOfYear = ldt.getDayOfYear();
        System.out.println("dayOfYear = " + dayOfYear);
        //获取是周几
        DayOfWeek dayOfWeek = ldt.getDayOfWeek();
        System.out.println("dayOfWeek = " + dayOfWeek);
        //时
        int hour = ldt.getHour();
        System.out.println("hour = " + hour);
        //分
        int minute = ldt.getMinute();
        System.out.println("minute = " + minute);
        //秒
        int second = ldt.getSecond();
        System.out.println("second = " + second);
        //纳秒
        int nano = ldt.getNano();
        System.out.println("nano = " + nano);

        // 2、修改时间信息：
        // withYear withMonth withDayOfMonth withDayOfYear withHour
        // withMinute withSecond withNano
        LocalDateTime newTime = ldt.withHour(3);
        System.out.println("newTime = " + newTime);

        // 3、加多少:
        // plusYears  plusMonths plusDays plusWeeks plusHours plusMinutes plusSeconds plusNanos
        LocalDateTime twoYears = ldt.plusYears(2);
        System.out.println("twoYears = " + twoYears);

        // 4、减多少：
        // minusDays minusYears minusMonths minusWeeks minusHours minusMinutes minusSeconds minusNanos
        LocalDateTime fiveYears = ldt.minusYears(5);
        System.out.println("fiveYears = " + fiveYears);


        // 5、获取指定日期和时间的LocalDateTime对象：
        // public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour,
        //                                  int minute, int second, int nanoOfSecond)
        LocalDateTime of = LocalDateTime.of(2018, 02, 03, 05, 20, 00);
        System.out.println("of = " + of);

        // 6、 判断2个日期、时间对象，是否相等，在前还是在后： equals、isBefore、isAfter
        System.out.println("ldt.isEqual(of) = " + ldt.isEqual(of));
        System.out.println("ldt.isAfter(of) = " + ldt.isAfter(of));
        System.out.println("ldt.isBefore(of) = " + ldt.isBefore(of));

        // 7、可以把LocalDateTime转换成LocalDate和LocalTime
        System.out.println("ldt = " + ldt);
        // public LocalDate toLocalDate()
        LocalDate date = ldt.toLocalDate();
        System.out.println("date = " + date);
        // public LocalTime toLocalTime()
        LocalTime time = ldt.toLocalTime();
        System.out.println("time = " + time);
        // public static LocalDateTime of(LocalDate date, LocalTime time)
        LocalDateTime localDateTime = LocalDateTime.of(date, time);
        System.out.println("localDateTime = " + localDateTime);

    }
}
